package com.itheima.config;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

/**
 * @author: dh
 * @date: 2023-11-07 17:06
 * 初始化Servlet容器
 */
public class ServletContainersInitConfig extends AbstractDispatcherServletInitializer {

    // 加载SpringMVC配置类.
    @Override
    protected WebApplicationContext createServletApplicationContext() {

        // 初始化WebApplocationContext对象
        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        // 加载指定配置类
        ctx.register(SpringMvcConfig.class);
        return ctx;
    }

    // 设置由springmvc控制器处理的请求映射路径
    @Override
    protected String[] getServletMappings() {

        return new String[] {"/"};
    }

    // 加载Spring配置类
    @Override
    protected WebApplicationContext createRootApplicationContext() {

        return null;
    }
}
